<template>
    <div>
     <header class="bar bar-nav" >
    <a class="button button-link button-nav pull-left" v-link="{path: '/user/userupgrad-2', replace: false}">
    <span class="icon icon-left"></span>
    </a>
    <h1 class="title">会员在线升级</h1>
  </header>
    <div class="content">
        <div class="card">
            <div class="card-header"><div class="header-css">生成订单</div></div>
            <div class="card-content">
              <div class="card-content-inner list-block" >
              <ul>
           <li>
             <div class="item-content">
               <div class="item-inner">
                  <div class="item-title label">商品名称：</div>
                  <div class="item-input">
                      {{goods}}
                  </div>
                </div>
              </div>
           </li>
	    <li>
             <div class="item-content">
               <div class="item-inner">
                  <div class="item-title label">待付金额：</div>
                  <div class="item-input">
                      {{price}}
                  </div>
                </div>
              </div>
           </li>
	   </ul>
            </div>
	    </div>
	    <div class="card-footer">
	     <a class="button button-success button-fill paybtn">微信支付</a>
	    </div>
        </div>
     </div>
 </div>
</template>
<script>
import $ from 'zepto'
export default {
  route: {
    data () {
      if (this.$route.query.type === '1') {
        this.$set('goods', '英盟MT')
      }
      if (this.$route.query.type === '2') {
        this.$set('goods', '英盟ME')
      }
      if (this.$route.query.type === '3') {
        this.$set('goods', '英盟PLUS')
      }
      this.$set('price', this.$route.query.price)
    }
  },
  ready () {
    $.init()
    const self = this
    $(document).on('click', '.paybtn', function () {
      self.$http.post(self.apiUrl + $.sign.openid, {price: 100 * (self.price), goods: self.goods}).
      then(function (response) {
        this.$set('order', response.json().ordermap)
        $.sign.sendpay(self.order)
      })
    })
  },
  data () {
    return {
      apiUrl: 'http://creatgo.com/oec/pay?method=jsapi&openid=',
      price: 0,
      goods: '',
      order: {}
    }
  }
}
</script>
<style scoped>
 .card-header{
   text-align:center;
 }
 .header-css{
  margin:0 auto;
  font-weight:bolder;
  color:red;

 }
 .paybtn{
  margin:0 auto;
 }
</style>
